﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PersonalHealth.Data.IService;
using PersonalHealth.Data.Service;
using PersonalHealth.Data.Model;
using HealthManagement.Common;
using HealthManagement.Models;
using UI.Comm.Controls;

namespace HealthManagement.Views
{
    /// <summary>
    /// MessageForm.xaml 的交互逻辑
    /// </summary>
    public partial class MessageForm : PMWindow
    {
        MeasureUser measureUser;
        public MessageForm(MeasureUser measureUser)
        {
            InitializeComponent();
            this.measureUser = measureUser;
            cboxType.ItemsSource = new string[] { "消息", "任务" };
            cboxType.SelectedIndex = 0;
        }

        public MessageForm(MsgTask obj)
        {
            InitializeComponent();
            lblTitle.Visibility = Visibility.Collapsed;
            cboxType.Visibility = Send.Visibility = Cancel.Visibility = Visibility.Collapsed;
            tbTitle.Value = obj.Title;
            tbText.Text = obj.Content;
            tbTitle.IsReadOnly = true;
            tbText.IsReadOnly = true;
        }

        private void Send_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(tbText.Text))
            {
                MessageBox.Show("内容不能为空！");
                return;
            }
            IDoctorService ser = new DoctorService();
            string title = tbTitle.Value == null ? "" : tbTitle.Value.ToString();
            if (cboxType.SelectedItem.ToString() == "消息")
            {
                ser.SendMessage(AppData.User.Id, measureUser.Id, title, tbText.Text);
            }

            if (cboxType.SelectedItem.ToString() == "任务")
            {
                ser.SendTask(measureUser.Id, title, tbText.Text);
            }

            this.Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
